$(function () {
  $("#goto-register").on("click", function () {
    $("#register").show();
  });
  $("#goto-login").on("click", function () {
    $("#register").hide();
  });
  let { form } = layui
  form.verify({
      username:[
          /^[a-z0-9]{6,10}$/,
          '账号名是6到10位由数字, 小写字母组成'
      ],
      password:[
          /^[\S]{6,10}$/,
          '密码是6到10位, 不能有空格'
      ],
      repwd:function(value){
          return value!==$('.pwd').val() && '两次输入的密码不一致'
      },
    })
    $('#register .layui-form').on('submit',async (e) => {
        e.preventDefault()
        let obj= {
            username:$('#register input[name="username"]').val(),
            password:$('#register input[name=password]').val()
        }
     let res = await reqPostRegister(obj)
     $('#register').hide()
     console.log(res.data);
     let {data : {message, status}}=res
     console.log(status);
			console.log(message);
            if(status===0) {
                layer.msg(message)
            }
    })  
    $('#login .layui-form').on('submit',async function(e) {
          e.preventDefault()
          let arr={
              username:$('#login input[name=username]'),
              password:$('#login input[name=password]')
          }
          console.log(arr);
          let res= await reqPostLogin(arr)
          console.log(res);
          localStorage.setItem('big-event-token',res.data.token)
          location.href='index.html'
          console.log('ok',res);
         let { data :{message, status}}=res
         if(status===0) {
             layer.msg(message)
             location.href='index.html'
         }
    })
});
